//
//  FLLWorksMoreTableViewCell.m
//  FLLGodOfCooking
//
//  Created by LL.F on 16/9/19.
//  Copyright © 2016年 LL.F. All rights reserved.
//

#import "FLLWorksMoreTableViewCell.h"
#import "FLLAgreeCollectionViewCell.h"
#import "FLLMacro.h"
#import "FLLPresentCollectionViewCell.h"

@interface FLLWorksMoreTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@end
@implementation FLLWorksMoreTableViewCell

- (void)awakeFromNib {
    // Initialization code
    
    
    self.agreeLayout.minimumInteritemSpacing = 0;
    self.agreeLayout.minimumLineSpacing = 10;
    self.agreeLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.agreeLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.agreeCollectionView.delegate = self;
    self.agreeCollectionView.dataSource = self;
    self.agreeCollectionView.backgroundColor = [UIColor whiteColor];
    self.agreeCollectionView.showsHorizontalScrollIndicator = NO;
    [self.agreeCollectionView registerNib:[UINib nibWithNibName:@"FLLAgreeCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"agreeCollectionCell"];
    
    self.moreWorksLayout.minimumInteritemSpacing = 0;
    self.moreWorksLayout.minimumLineSpacing = 0;
    self.moreWorksLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.moreWorksLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.moreWorksCollectionVIew.delegate = self;
    self.moreWorksCollectionVIew.dataSource = self;
    self.moreWorksCollectionVIew.backgroundColor = [UIColor whiteColor];
    self.moreWorksCollectionVIew.showsHorizontalScrollIndicator = NO;
    [self.moreWorksCollectionVIew registerNib:[UINib nibWithNibName:@"FLLPresentCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"presentCollectionCell"];
    

}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    if (collectionView == _agreeCollectionView) {
        if (self.agreeCollectionData.count >= 5) {
            return 5;
        }
        return self.agreeCollectionData.count;
    }
    return self.moreWorksCollectionData.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    if (collectionView == _agreeCollectionView) {
        FLLAgreeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"agreeCollectionCell" forIndexPath:indexPath];
        
        [cell.userImageView sd_setImageWithURL:[NSURL URLWithString:self.agreeCollectionData[indexPath.row].head_img] placeholderImage:[UIImage imageNamed:@"userHeadImage-1"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            
        }];
        return cell;
    }
    FLLPresentCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"presentCollectionCell" forIndexPath:indexPath];
    [cell.mainImageView sd_setImageWithURL:[NSURL URLWithString:_moreWorksCollectionData[indexPath.row].image] placeholderImage:[UIImage imageNamed:@"菜谱详情加载"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
    return cell;
    
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (collectionView == _agreeCollectionView) {
        CGFloat width = self.agreeCollectionView.bounds.size.height;
        return CGSizeMake(width, width);
    }
    CGFloat width = self.moreWorksCollectionVIew.bounds.size.height;
    return CGSizeMake(width, width);
    
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *string = self.moreWorksCollectionData[indexPath.row].id_Data;
    self.moreBlock(string);
    
}
- (void)setAgreeCollectionData:(NSMutableArray<WorksLike *> *)agreeCollectionData
{

    _agreeCollectionData = agreeCollectionData;
    [self.agreeCollectionView reloadData];
}
- (void)setMoreWorksCollectionData:(NSMutableArray<WorksRelates *> *)moreWorksCollectionData
{

    _moreWorksCollectionData = moreWorksCollectionData;
    [self.moreWorksCollectionVIew reloadData];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
